package com.xhd.xml;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Vector;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import com.xhd.base.log.Log;
import com.xhd.base.log.LogFactory;
import com.xhd.base.util.xBaseObj;
import com.xhd.codec.CryptoFilter;
import com.xhd.exception.XException;
import com.xhd.exception.XMLException;
import com.xhd.file.XZipFile;
import com.xhd.server.ServerConfig;
import com.xhd.util.DataRelation;
import com.xhd.util.ObjectSerializer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

public class XMLSerializer implements ObjectSerializer {

	public InputStream in;
	private Document XmlDoc;
	private CryptoFilter CryFilter = null;
	private static final Log logobj;
	static Class XMLSerializerclass;
	static Class jm17;

	static {
		Class tempclas = XMLSerializerclass;
		if (tempclas == null) {
			try {
				XMLSerializer.XMLSerializerclass = Class
						.forName("com.sinocc.base.xml.XMLSerializer");
			} catch (ClassNotFoundException localClassNotFoundException) {
				throw new NoClassDefFoundError(
						localClassNotFoundException.getMessage());
			}
		}
		logobj = LogFactory.getLog(tempclas);
	}

	public XMLSerializer() {
	}

	public XMLSerializer(InputStream paramInputStream) throws XException {
		int i = -1;
		try {
			while (true) {
				i = paramInputStream.read();
				if (i == -1)
					throw new XMLException(70031);
				if (i != 2) {
					if (i != 1)
						continue;
					break;
				}
			}
		} catch (Exception localException1) {
		}
		label51:
		;
		// label51: Object localObject;
		if (i == 2) {
			XZipFile localObject = new XZipFile();
			this.in = ((XZipFile) localObject).unzipFile(paramInputStream);
		} else {
			this.in = paramInputStream;
		}
		try {
			DocumentBuilderFactory localObject = DocumentBuilderFactory
					.newInstance();
			DocumentBuilder localDocumentBuilder = ((DocumentBuilderFactory) localObject)
					.newDocumentBuilder();
			InputSource localInputSource = new InputSource(this.in);
			this.XmlDoc = localDocumentBuilder.parse(localInputSource);
		} catch (Exception localException2) {
			logobj.error(localException2);
			throw new XMLException(70031);
		}
	}

	public XMLSerializer(InputStream paramInputStream, boolean paramBoolean)
			throws XException {
		Object localObject;
		if (paramBoolean) {
			localObject = new XZipFile();
			this.in = ((XZipFile) localObject).unzipFile(paramInputStream);
		} else {
			this.in = paramInputStream;
		}
		try {
			localObject = DocumentBuilderFactory.newInstance();
			DocumentBuilder localDocumentBuilder = ((DocumentBuilderFactory) localObject)
					.newDocumentBuilder();
			InputSource localInputSource = new InputSource(this.in);
			this.XmlDoc = localDocumentBuilder.parse(localInputSource);
		} catch (Exception localException) {
			logobj.error(localException);
			throw new XMLException(70031);
		}
	}

	public XMLSerializer(String paramString) throws XException {
		if ((paramString == null) || (paramString.length() < 1))
			throw new XMLException(70031);
		try {
			DocumentBuilderFactory localDocumentBuilderFactory = DocumentBuilderFactory
					.newInstance();
			DocumentBuilder localDocumentBuilder = localDocumentBuilderFactory
					.newDocumentBuilder();
			ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(
					paramString.getBytes(ServerConfig.XMLEncode));
			this.XmlDoc = localDocumentBuilder.parse(localByteArrayInputStream);
		} catch (Exception localException) {
			logobj.error(localException);
			throw new XMLException(70031);
		}
	}

	public XMLSerializer(Document paramDocument) {
		this.XmlDoc = paramDocument;
	}


	@Override
	public Object serializeObject(xBaseObj paramBusinessClass, int paramInt)
			throws XException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object serializeObject(Throwable paramThrowable, int paramInt) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void instanceObject(xBaseObj paramBusinessClass) throws XException {
		// TODO Auto-generated method stub

	}

	@Override
	public void instanceRelationObject(DataRelation paramDataRelation)
			throws XException {
		// TODO Auto-generated method stub

	}

	@Override
	public String getData(String paramString) throws XException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setFilter(CryptoFilter paramCryptoFilter) {
		// TODO Auto-generated method stub

	}
	  public Vector getCollection(String paramString)
	    throws XException
	  {
	    DataRelation localDataRelation = new DataRelation(paramString);
	    instanceRelationObject(localDataRelation);
	    return localDataRelation.getRelationData();
	  }
	  
	
}
